<?php
class arcService extends commonService{
	public function __construct(){
		parent::__construct();
		$this->table=table('arc');
        $this->table_data=table('arc_data');
		$this->table_fav=table('favorite');
	}
	public function mylist($condition=array(),$extra=''){
        $return=array();
        $query="select `id`,`title`,`add_time`,`hits` from `{$this->table}` where 1 {$extra} order by `id` desc";
        
        $total=$this->_total($query);
		$ret=$this->_page($total,10);
		$pager=$this->pager($ret);
        
        if($total>0){
            $query=$query." limit {$ret['c']}";
            $return[]=$this->m->mselect($query);
            $return[]=$pager;
        }

        return $return;
    }
    public function show($id){
        $query="select `a`.*,`b`.`content_cpl` as `body` from `{$this->table}` `a` left join `{$this->table_data}` `b` on `a`.`id`=`b`.`id` where `a`.`id`='{$id}' and `a`.`status`='1' limit 1";
        return $this->m->select($query);
    }
	//输出并更新文章点击次数
	public function update_arc_hits($id){
		if($id<=0) return false;
		$query="update `{$this->table}` set `hits`=`hits`+1 where `id`='{$id}' limit 1";
		$this->m->query($query);
	}
		
	//文章收藏部分
	public function favorite($id){
		$query="select `id`,`title`,`htmlurl` from `{$this->table}` where `status`='1' and `id`='{$id}' limit 1";
		return $this->m->select($query);
	}
	public function favorite_($arc_id,$user_id,$d){
		$d['user_id']=intval($user_id);
		$d['timestring']=time();
		$d['arc_id']=intval($arc_id);
		
		$d['title']=addslashes($d['title']);
		$d['htmlurl']=addslashes($this->conf->WEB['url'].trim($d['htmlurl'],'/'));
		
		$query="select `id` from `{$this->table_fav}` where `arc_id`='{$d['arc_id']}' and `user_id`='{$d['user_id']}' limit 1";
		$r=$this->m->get_field($query);
		if($r>0) return true;
		
		return $this->model->_i($this->table_fav,$d);
	}
//
}